package ar.com.sectorwine.dto;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Repository;

import ar.com.sectorwine.entities.Stock;

@Repository
public class StockDTOMapper {

	public Stock obtenerObjetoDelDominioDesdeDTO(StockDTO stockDTO) {

		Stock newstock = new Stock();

		newstock.setId(stockDTO.getId());
		newstock.setVariedad(stockDTO.getVariedad());
		newstock.setColor(stockDTO.getColor());
		newstock.setAcidez(stockDTO.getAcidez());
		newstock.setAlcohol(stockDTO.getAlcohol());
		newstock.setAzucar(stockDTO.getAzucar());
		newstock.setCantidad(stockDTO.getCantidad());
		newstock.setEdad(stockDTO.getEdad());
		newstock.setIdINV(stockDTO.getIdINV());
		newstock.setPrecio(stockDTO.getPrecio());

		SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy"); 
		try {
			newstock.setVencimiento(sdf.parse(stockDTO.getVencimiento()));
		} catch (ParseException e) {
			newstock.setVencimiento(new Date());
			e.printStackTrace();
		}

		return newstock;

	}
}
